package niuke;

import java.util.Scanner;

public class 跳石板 {

    static long min = 999999999;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int start = scanner.nextInt();
        int end = scanner.nextInt();
        f(start,end,0);
        if(min == 999999999){
            min = -1;
        }
        System.out.println(min);
    }

    public static void f(int start,int end,long count){
        if(count>min)
            return;
        if(start == end) {
            if(count<min)
                min = count;
            return;
        }
        int i = (end/2)+1;
        for(;i<=end-2;i++){
            //判断越界
            if(i<start)
                continue;
            //判断可以走
            if(i%(end-i) == 0)
                f(start,i,count+1);
        }
    }
}
